// 判断用户是否绑定了手机号码

const isBindPhone = function() {
	// 判断用户是否已绑定手机号，未绑定手机号，跳转至手机号绑定页面
	let userInfo = uni.getStorageSync('userInfo')

	let userMsg = uni.getStorageSync('userMsg')

	let phone = uni.getStorageSync('phone')


	if (userMsg) {
		userMsg = JSON.parse(userMsg)
	}


	let wxcathePhone = null

	if (userInfo.phone) {
		wxcathePhone = userInfo.phone
	} else if (userMsg) {
		wxcathePhone = userMsg.phone
	} else {
		wxcathePhone = phone
	}

	if (wxcathePhone) {
		return true;
	} else {
		return false;
	}


}

// 用户查看招标详情或企业详情达到限制

const memberTip = function() {

	if (uni.getStorageSync('vipEndTime')) {
		uni.showModal({
			title: '查阅已达上限',
			content: '尊敬的才能招标用户，为保证用户的合理有效使用原则，会员每天查看100条信息，如更多需求，请联系客服！',
			success: function(res) {
				if (res.confirm) {
					console.log('用户点击确定');
					// 拨打客服联系电话
					// this.callPhone('400-0731-057')
					// #ifdef MP-WEIXIN
					uni.makePhoneCall({
						phoneNumber: '400-0731-057'
					});
					// #endif
					//安卓手机手动设置一个showActionSheet
					//   #ifdef APP-PLUS
					uni.showActionSheet({
						itemList: ['400-0731-057', '呼叫'],
						success: function(res) {
							console.log(res);
							if (res.tapIndex == 1) {
								uni.makePhoneCall({
									phoneNumber: '400-0731-057',
								})
							}
						}
					})
					// #endif
				} else if (res.cancel) {
					console.log('用户点击取消');
					uni.navigateBack({
						delta: 1
					});
				}
			}
		});
	} else {
		uni.showModal({
			title: '查阅已达上限',
			content: '尊敬的才能招标用户，为保证用户的合理有效使用原则，每天免费查看10条信息，如更多需求，请充值会员！',
			success: function(res) {
				if (res.confirm) {
					console.log('用户点击确定');
					// 跳转至充值页面
					uni.navigateTo({
						url: `/pagesUser/rember/rember?last=1`
					})
				} else if (res.cancel) {
					console.log('用户点击取消');
					uni.navigateBack({
						delta: 1
					});
				}
			}
		});
	}
}

const getNotionNews = function(that,callBack){
	if (uni.getStorageSync('isLogin')!=1){
		return
	}
	// console.log('00000000000000000000')
	let param = {
		page: 1,
		pageSize: 10
	}
	that.$app.request({
		url: that.$baseApp.api.user.findNoReadCount,
		data: param,
		method: 'GET',
		dataType: 'json',
		success: res => {
			// console.log("这里是查询用户消息", res)
		
			if(res.data>0){
				uni.showTabBarRedDot({
				  index: 2
				})
				
			}
			if(callBack){
				callBack(res.data)
			}
			
			
		}
	});
} 

export default {
	isBindPhone,
	memberTip,
	getNotionNews
};
